package cn.lg.soar.activiti.feign;

import cn.lg.soar.activiti.api.constant.ModuleConst;
import cn.lg.soar.activiti.api.model.*;
import cn.lg.soar.activiti.api.service.IActivitiApi;
import cn.lg.soar.activiti.feign.fallback.ActivitiApiFallbackFactory;
import cn.lg.soar.core.annotations.ApiClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Collection;
import java.util.List;

/**
 * 文件上传接口
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@ConditionalOnMissingClass("cn.lg.soar.activiti.client.ActivitiApiClient")
@ApiClient
@FeignClient(
        name= ModuleConst.MODULE_NAME,
        path= ModuleConst.CLIENT_PATH + "/activiti",
        fallbackFactory= ActivitiApiFallbackFactory.class,
        contextId="ActivitiApiFeign"
)
public interface ActivitiApiFeign extends IActivitiApi {

    /**
     * 启动流程
     * @param dto
     * @return
     */
    @PostMapping("startProcess")
    ProcessInstanceDTO startProcess(@RequestBody StartProcessDTO dto);

    /**
     * 完成任务
     * @param dto
     */
    @PostMapping("completeTask")
    void completeTask(@RequestBody CompleteTaskDTO dto);

    /**
     * 查询任务列表
     * @param processKey 流程key
     * @param businessIds 业务id
     * @param candidates 候选人，用户：username，角色：R:roleCode，组织机构：O:orgId
     * @return
     */
    @GetMapping("tasks")
    List<TaskDTO> tasks(
            @RequestParam("processKey") String processKey,
            @RequestParam("businessIds") Collection<String> businessIds,
            @RequestParam("assigned") Collection<String> candidates
    );

    /**
     * 历史任务（审批日志）
     * @param processKey 流程key
     * @param businessId 业务id
     * @return
     */
    @GetMapping("historyTasks")
    List<HistoryTaskDTO> historyTasks(
            @RequestParam("processKey") String processKey,
            @RequestParam("businessId") String businessId
    );

}
